<template>
    <div class="r_main">
        <div class="form_con">
            <div class="outer">
                <div class="y1">
                    <div>
                        <div class="list" v-for="(item, index) in list" :key="item.id">
                            <lExcerpt v-if="(index + 1) % 2 != 0" :maxWidth="200" :list="item" @reList="getExpId">
                            </lExcerpt>
                        </div>
                    </div>
                    <div>
                        <div class="list" v-for="(item, index) in list" :key="item.id">
                            <lExcerpt v-if="(index + 1) % 2 == 0" :maxWidth="200" :list="item" @reList="getExpId">
                            </lExcerpt>
                        </div>
                    </div>
                </div>


            </div>
            <el-empty description="没有内容了" v-if="list.length == 0"></el-empty>

        </div>

    </div>

</template>
<script>
import lExcerpt from "./l-excerpt"
export default {
    components: {
        lExcerpt
    },
    data() {
        return {
            list: [],
            dialogVisible: false,
            form: { type: '' },
            pageNum: 1,
            totalPage: 1,
            loading: false,
            total: 0,
            new_id: 0
        }
    },
    computed: {
        path() {
            return this.$route.path
        }
    },
    props: {
        id: {
            type: Number || String,
            default: 0,
        }
    },
    mounted() {
        let id = this.$route.query.id
        if (id) {
            this.new_id = id
            this.pageNum = 1
        }
        this.getList()

        window.addEventListener('scroll', this.handleScroll); // 监听滚动事件

    },
    beforeDestroy() {
        window.removeEventListener('scroll', this.handleScroll); // 移除监听
    },

    methods: {
        getExpId(info) {
            let list = this.list
            let id = info.id
            let op = info.op
            let status = info.status

            list.forEach((i, d) => {
                if (id == i.id) {
                    if (op == 2) {
                        this.list[d].is_like = status
                        // 点赞
                        if (status == 1) {
                            this.list[d].likes += 1
                        } else {
                            this.list[d].likes -= 1
                        }
                    } else {
                        // 展开
                        this.list[d].views += 1
                    }
                }
            })
        },
        // 摘抄
        getList() {
            this.loading = true
            let params = {
                page: this.pageNum,
                id: this.id != 0 ? this.id : this.new_id
            }
            this.$api.getVipExcerpt(params).then(res => {
                if (res.data.code == 1) {
                    this.list = []
                    this.totalPage = res.data.data.last_page
                    this.list = this.list.concat(res.data.data.data);
                    this.total = res.data.data.total
                    this.loading = false
                }

            })
        },
        getTabtype(t) {
            this.curType = t
        },
        load() {
            console.log("处理触底");
            var page = this.pageNum
            //如果请求未结束就返回不连续请求
            if (this.loading) {
                return
            }
            //数据请求完成无更多数据时
            if (page >= this.totalPage) {
                return false;
            }
            page = parseInt(page) + 1
            this.pageNum = page
            this.getList()
        },
        onsubmit() {
            console.log(this.form);

        },
        handleScroll() {
            const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
            const windowHeight = window.innerHeight;
            const scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
            // 判断是否滚动到底部
            if (scrollTop + windowHeight >= scrollHeight - 20) {
                this.load()
            }
        },
    }
}
</script>
<style lang="scss" scoped>
.r_main {
    width: 100%;

    .user {
        width: 100%;
        height: 200px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        position: relative;
        padding: 0 30px;
        overflow: hidden;
        background: linear-gradient(to right, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0));

        .bgg {
            position: absolute;
            width: 100%;
            height: auto;
            z-index: -1;

        }

        .left {
            display: flex;
            color: #fff;
            align-items: center;

            .avatar {
                width: 150px;
                height: 150px;
                margin-right: 27px;
                flex-shrink: 0;
                border-radius: 50%;
                overflow: hidden;

                img {
                    object-fit: cover;
                    width: 100%;
                    height: 100%;
                }
            }

            .info {
                .nane {
                    font-weight: bold;
                    font-size: 30px;
                    color: #FFFFFF;
                    margin-bottom: 13px;
                }

                .data {
                    display: flex;
                    align-items: center;
                    margin-bottom: 13px;

                    .line {
                        height: 18px;
                        display: block;
                        width: 2px;
                        background-color: #fff;
                        margin: 0 18px;
                    }

                    >div {
                        font-weight: 400;
                        font-size: 18px;
                        color: #999999;

                        >span {
                            color: #FFFFFF;
                        }
                    }
                }

                .address {
                    display: flex;
                    align-items: center;
                    margin-bottom: 10px;
                    font-weight: 400;
                    font-size: 16px;
                    color: #999999;

                    .line {
                        margin: 0 18px;
                        display: block;
                        height: 16px;
                        width: 2px;
                        background-color: #999;
                    }
                }

                .sign {
                    font-weight: 400;
                    font-size: 16px;
                    color: #FFFFFF;
                }
            }
        }

        .right {
            height: 100%;
            padding: 28px 0 38px;
            font-weight: 400;
            display: flex;
            justify-content: space-between;
            align-items: flex-end;
            flex-direction: column;
            font-size: 20px;
            color: #FFFFFF;

            .share {
                cursor: pointer;
                display: flex;
                align-items: center;
                justify-content: center;

                img {
                    width: 28px;
                    height: auto;
                    margin-left: 11px;
                }
            }

            .btn {
                display: flex;
                align-items: center;
                justify-content: center;

                button {
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    width: 120px;
                    height: 48px;
                    background: #F98951;
                    border-radius: 24px;
                    opacity: 0.9;
                    margin-left: 26px;
                    font-weight: 400;
                    font-size: 20px;
                    color: #FFFFFF;
                    border: none;

                    &:nth-child(2) {
                        background: #1068E7;
                    }
                }
            }
        }
    }

    .tabIn {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 23px 0;
        background-color: #fff;
        position: sticky;
        top: 99px;
        z-index: 99;

        .tab {
            display: flex;
            align-items: center;

            >div {
                font-size: 24px;
                display: flex;
                flex-direction: column;
                align-items: center;
                margin-right: 55px;
                cursor: pointer;
                position: relative;

                .actives {
                    font-weight: bold;
                    color: #1068E7;
                }

                .botLine {
                    width: 100%;
                    height: 3px;
                    box-sizing: content-box;
                    position: relative;
                    top: calc(100% + 13px);
                    position: absolute;
                    left: 0;
                    right: 0;

                    >span {
                        position: absolute;
                        left: 0;
                        top: 0;
                        display: inline-block;
                        width: 0;
                        height: 3px;
                        background-color: #1068E7;
                        border-radius: 3px;
                    }

                    .active {
                        animation: expandWidth .5s forwards;
                    }

                    @keyframes expandWidth {
                        0% {
                            width: 0;
                        }

                        100% {
                            width: 100%;
                        }
                    }
                }
            }
        }

        .search {
            margin-left: 4.4rem;
            position: relative;
            width: 280px;
            height: 48px;
            display: flex;
            align-items: center;

            img {
                width: 23px;
                height: 23px;
                position: absolute;
                top: calc(50% - 11px);
                right: 11px;
            }

            input {
                width: 280px;
                height: 48px;
                outline: none;
                background: #F6F6F6;
                border-radius: 1.25rem;
                padding: 0 3rem 0 1.2rem;
                box-sizing: border-box;
                font-size: 0.83rem;
                border: none;
                border: 1px solid #F6F6F6;

                &:focus {
                    border: 1px solid #1068E7;
                }
            }

            .pla {
                font-weight: 400;
                font-size: 0.83rem;
                color: #666666;
            }
        }
    }

    .form_con {
        min-height: 500px;
        // overflow-y: auto;
    }
}

.outer {
    display: flex;
    align-items: flex-start;
    padding-bottom: 20px;

    .y1 {
        width: 100%;
        display: flex;
        flex-wrap: wrap;

        >div {
            width: calc(50% - 12.5px);

            &:nth-child(2n) {
                margin-left: 25px;
            }
        }
    }

    .list {
        display: flex;
        align-items: flex-start;
        flex-wrap: wrap;
        width: 100%;

        .title {
            display: flex;
            align-items: center;
            font-weight: 400;
            font-size: 18px;
            color: #000000;

            img {
                width: 16px;
                height: auto;
                margin-right: 16px;
            }

            .name {
                width: 700px;
            }
        }

        .set {
            display: flex;
            align-items: center;
            justify-content: space-between;
            flex: 1;

            .data {
                font-size: 16px;
                color: #999;
                display: flex;
                align-items: center;

                >span {
                    display: inline-block;
                    flex-shrink: 0;
                }

                .dz {
                    margin-right: 15px;
                    width: 100px;
                    text-align: center;
                }

                .line {
                    width: 2px;
                    height: 15px;
                    background-color: #999;
                }

                .nums {
                    width: 120px;
                    text-align: center;
                }

                .nickname {
                    margin-left: 15px;
                }
            }

            .btn {
                display: flex;

                .price {
                    font-size: 20px;
                    color: #D31B23;
                    margin-right: 50px;
                }

                button {
                    width: 80px;
                    height: 30px;
                    background-color: #1169E5;
                    border: none;
                    border-radius: 5px;
                    color: #fff;
                }
            }
        }
    }
}
@media screen and (max-width:768px) {
    .outer .y1 > div{
        width: 100%;
    }
}
</style>